package com.anlogic.sdk.openocd.model;

import com.google.gson.Gson;

public class RemoteTarget {
	public static final String LOCAL_NAME = "Local";
	public static final String LOCALHOST = "localhost";
	public static final String LOCALHOST_IP = "127.0.0.1";
	
	private String name;
	private String host;
	private String port;
	private boolean isDefault;
	private JtagCable cable;
	
	public RemoteTarget() {
		this.name = "Local";
		this.host = "localhost";
		this.port = "3333";
		this.isDefault = true;
	}

	public RemoteTarget(String name, String host, String port, boolean isDefault) {
		this.name = name;
		this.host = host;
		this.port = port;
		this.isDefault = isDefault;
	}
	
	public boolean isDefaultLocal() {
		return this.name.equals(LOCAL_NAME);
	}
	
	public boolean isLocal() {
		if (this.host.equals(LOCALHOST) || this.host.equals(LOCALHOST_IP)) {
			return true;
		}
		return false;
	}
	
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHost() {
		return this.host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getPort() {
		return this.port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public boolean isDefault() {
		return this.isDefault;
	}

	public void setAsDefault(boolean isDefault) {
		this.isDefault = isDefault;
	}
	
	public JtagCable getCable() {
		return this.cable;
	}

	public void setCable(JtagCable cable) {
		this.cable = cable;
	}
	
	public String toJsonString() {
		Gson gson = new Gson();
		return gson.toJson(this);
	}
	
	public RemoteTarget readJsonString(String json) {
		Gson gson = new Gson();
		return gson.fromJson(json, RemoteTarget.class);
	}
}
